var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("UIBase"),
    s = t("UIConfig"),
    c = t("UIManager"),
    p = t("UpdatePosBean"),
    l = t("DlgNode"),
    d = cc._decorator,
    u = d.ccclass,
    h =
        (d.property,
        d.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.posCheck = new p.default();
                e.moveList = [];
                e.baseList = [];
                e.isResetRoom = !1;
                e.playIndex = 0;
                e.lastPos = 0;
                e.isUpdate = !1;
                return e;
            }
            e.prototype.onShowEnd = function () {
                var t = this;
                GameDataValue.setFirstOpenKey(!1);
                this._ScrollView.opacity = 0;
                this.updateViewRoom();
                this.scheduleOnce(function () {
                    t._ScrollView.opacity = 255;
                    t.updatePos();
                }, 0.1);
                this.updateChapterName();
                var e = this.ui_data.lvIndex;
                this._ScrollView.$ScrollView.scrollTo(cc.v2(0, 0.18 * e));
                this.isResetRoom = 7 == e;
                this.isResetRoom && (this._close.active = !1);
                this.resetPosList(e, this.ui_data.isPlay);
            };
            e.prototype.updateChapterName = function () {
                var t = this.ui_data.lv,
                    e = 8001 + Math.floor(t / 7) + "",
                    o = CacheDataManager.getChapter(e);
                this._tipLab.$Label.string = o.city_name;
                SpriteView.setTaskSprite(this._chapterSprite.$Sprite, o.icon);
            };
            e.prototype.updateViewRoom = function () {
                for (
                    var t = this.ui_data.lv,
                        e = 8001 + Math.floor(t / 7) + "",
                        o = (t % 7) + 1,
                        a = CacheDataManager.getChapter(e),
                        i = CacheDataManager.getRestaurantBaseData(),
                        n = 1;
                    n <= 7;
                    n++
                ) {
                    var r = "restaurant_id" + n,
                        s = i[a[r]].icon,
                        c = this._room.getChildByName("room" + n),
                        p = c.getComponentInChildren(cc.Sprite);
                    if (p) {
                        SpriteView.setTaskSprite(p, s);
                        var d = c.getComponentInChildren(l.default);
                        if (n <= o) {
                            d.node.active = !0;
                            d.setLab(i[a[r]].desc);
                            CacheDataManager.setSpriteMat(p, !0);
                        } else {
                            d.node.active = !1;
                            CacheDataManager.setSpriteMat(p, !1);
                        }
                    }
                }
            };
            e.prototype.updatePos = function () {
                for (var t = this.getAllMoveList(this._bgLine), e = 0; e < t.length; e++)
                    this.drawLine(this._bgLine.$Graphics, t[e], 0 == e);
            };
            e.prototype.resetPosList = function (t, e) {
                this.playPos(t, e);
            };
            e.prototype.playPos = function (t, e) {
                for (var o = this, a = this.getAllMoveList(this._Line), i = t - 1, n = 0; n < a.length && n < i; n++)
                    for (var r = 0; r < a[n].length; r++) this.baseList.push(a[n][r]);
                this.moveList.length = 0;
                for (n = i; n >= 0 && n < a.length && n < t; n++)
                    for (r = 0; r < a[n].length; r++) this.moveList.push(a[n][r]);
                this.playIndex = 0;
                if (this.moveList.length > 0) {
                    e && (this.playIndex = this.moveList.length - 1);
                    this.posCheck.setBasePos(cc.v2(this.moveList[this.playIndex].x, this.moveList[this.playIndex].y));
                } else {
                    var s = this._Line.$Graphics;
                    s.clear();
                    var c = a[0][0];
                    this.posCheck.setBasePos(cc.v2(c));
                    s.circle(c.x, c.y, 30);
                    s.fill();
                }
                e
                    ? (this.isUpdate = !0)
                    : this.scheduleOnce(function () {
                          o.isUpdate = !0;
                      }, 1);
                this.checkPos();
            };
            e.prototype.checkPos = function () {
                var t = this;
                if (this.playIndex < this.moveList.length) {
                    var e = this.moveList[this.playIndex];
                    this.playIndex++;
                    this.posCheck.moveToPos(cc.v2(e.x, e.y), 250, this.checkPos.bind(this));
                } else {
                    this.updateDataView();
                    this.isUpdate = !1;
                    if (this.isResetRoom) {
                        this.isResetRoom = !1;
                        this._carCat.$Animation.play();
                        this.scheduleOnce(function () {
                            c.default.open(s.UIID.UIRotateLoad, {cb: t.ui_data.cb});
                            t.closeUI();
                        }, 1);
                    }
                }
            };
            e.prototype.updateDataView = function () {
                var t = this._Line.$Graphics;
                t.clear();
                if (this.baseList.length > 0) {
                    t.moveTo(this.baseList[0].x, this.baseList[0].y);
                    for (var e = 1; e < this.baseList.length; e++) t.lineTo(this.baseList[e].x, this.baseList[e].y);
                    t.stroke();
                }
                var o = this.posCheck.moveBasePos();
                if (this.moveList.length > 0) {
                    t.moveTo(this.moveList[0].x, this.moveList[0].y);
                    for (e = 1; e < this.moveList.length && e < this.playIndex - 1; e++)
                        t.lineTo(this.moveList[e].x, this.moveList[e].y);
                    t.lineTo(o.x, o.y);
                    t.stroke();
                }
                t.circle(o.x, o.y, 30);
                t.fill();
            };
            e.prototype.update = function (t) {
                if (this.isUpdate) {
                    this.posCheck.update(t);
                    this.posCheck.isMove() && this.moveList.length > 0 && this.updateDataView();
                }
            };
            e.prototype.getAllMoveList = function (t) {
                for (var e = [], o = 0; o < t.childrenCount; o++) {
                    var a = t.children[o];
                    if (a.childrenCount > 1) {
                        for (var i = [], n = 0; n < a.childrenCount; n++) i.push(this.getPos(a.children[n], t));
                        e.push(i);
                    }
                }
                return e;
            };
            e.prototype.getPos = function (t, e) {
                var o = t.convertToWorldSpaceAR(cc.Vec2.ZERO),
                    a = e.convertToNodeSpaceAR(o);
                return {x: a.x, y: a.y};
            };
            e.prototype.drawLine = function (t, e, o, a, i) {
                void 0 === o && (o = !0);
                void 0 === a && (a = !1);
                void 0 === i && (i = !1);
                o && t.clear();
                if (e.length > 1) {
                    var n = e.shift();
                    t.moveTo(n.x, n.y);
                    e.forEach(function (e) {
                        t.lineTo(e.x, e.y);
                    });
                    a && t.close();
                    t.stroke();
                    i && t.fill();
                } else if (1 == e.length) {
                    t.circle(e[0].x, e[0].y);
                    t.fill();
                }
            };
            return n([u], e);
        })(r.default));
o.default = h;
